*******************************************************************************************************************************
*******************************************************************************************************************************
* Documentation for Reproduction of
* Denny 2012 TESS Survey Experiment
* TESS Race Discrimination Meta-Analysis
* Stata version 15
* Data available here: http://www.tessexperiments.org/data/denny262.html
*******************************************************************************************************************************
*******************************************************************************************************************************

* use "TESS2_108_Denny_Client.dta", clear
set more off

*******************************************************************************************************************************
*** Racial groups
*******************************************************************************************************************************

tab PPETHM
gen whiteR = PPETHM
recode whiteR (2/5=0)
tab PPETHM whiteR
gen blackR = PPETHM
recode blackR (1 3/5=0) (2=1)
tab PPETHM blackR
gen hispnR = PPETHM
recode hispnR (1/3 5=0) (4=1)
tab PPETHM hispnR

*******************************************************************************************************************************
*** Treatments
*******************************************************************************************************************************

tab XTESS108
gen whiteT = 0
gen blackT = 0
gen hispanicT = 0
gen asianT = 0
replace whiteT = 1 if XTESS108==1 | XTESS108==5 | XTESS108==9
replace blackT = 1 if XTESS108==2 | XTESS108==6 | XTESS108==10
replace hispanicT = 1 if XTESS108==3 | XTESS108==7 | XTESS108==11
replace asianT = 1 if XTESS108==4 | XTESS108==8 | XTESS108==12
gen nokidsT = 0
gen kidsnotinvT = 0
gen kidsinvT = 0
replace nokidsT = 1 if XTESS108==1 | XTESS108==2 | XTESS108==3 | XTESS108==4
replace kidsnotinvT = 1 if XTESS108==5 | XTESS108==6 | XTESS108==7 | XTESS108==8
replace kidsinvT = 1 if XTESS108==9 | XTESS108==10 | XTESS108==11 | XTESS108==12

*******************************************************************************************************************************
*** Outcome variables
*******************************************************************************************************************************

tab1 Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 Q9 Q10
recode Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 Q9 Q10 (-1=.)
tab1 Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 Q9 Q10

alpha Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 Q9 Q10
alpha Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 Q9 Q10, item
alpha Q1 Q2 Q3 Q4 Q5, item
alpha Q1 Q2 Q3 Q4 Q5, item std min(3) gen(character)
egen character_std = std(character)

gen Q6_rev = 0 - Q6
alpha Q6_rev Q7 Q8 Q9 Q10, item std min(3) gen(hire)
egen hire_std = std(hire)

alpha Q1 Q2 Q3 Q4 Q5 Q6_rev Q7 Q8 Q9 Q10, item std min(5) gen(ALPHA)

sum ALPHA if whiteR==1
di r(sd)
gen ov_white_std = ALPHA/r(sd) if whiteR==1

sum ALPHA if blackR==1
di r(sd)
gen ov_black_std = ALPHA/r(sd) if blackR==1

sum ALPHA if hispnR==1
di r(sd)
gen ov_hispn_std = ALPHA/r(sd) if hispnR==1

*******************************************************************************************************************************
*** Racial manipulation check
*******************************************************************************************************************************

// No racial manipulation check

*******************************************************************************************************************************
*** Main regressions [Unweighted]
*******************************************************************************************************************************

reg ov_white_std blackT hispanicT asianT kidsnotinvT kidsinvT if (whiteT==1 | blackT==1) & whiteR==1
reg ov_black_std blackT hispanicT asianT kidsnotinvT kidsinvT if (whiteT==1 | blackT==1) & blackR==1
reg ov_hispn_std blackT hispanicT asianT kidsnotinvT kidsinvT if (whiteT==1 | blackT==1) & hispnR==1

*******************************************************************************************************************************
*** Test for ingroup / outgroup difference [Unweighted]
*******************************************************************************************************************************

reg ov_black_std blackT hispanicT asianT kidsnotinvT kidsinvT if (hispanicT==1 | blackT==1) & blackR==1
reg ov_black_std blackT hispanicT asianT kidsnotinvT kidsinvT if (asianT==1 | blackT==1) & blackR==1
sum ov_black_std if whiteT==1
sum ov_black_std if blackT==1
sum ov_black_std if hispanicT==1
sum ov_black_std if asianT==1
